import 'package:flutter/material.dart';
import 'package:xinxuan/common/button_util.dart';
import 'package:xinxuan/common/replacement_agreement.dart';
import 'package:xinxuan/common/scroll_configuration_common.dart';
import 'package:xinxuan/common/seckill_order_detail_goods_arr.dart';
import 'package:xinxuan/common/seckill_order_detail_info_body.dart';
import 'package:xinxuan/common/seckill_order_detail_info_item.dart';
import 'package:xinxuan/controllers/order_controller/seckill_order_detail_page_controller.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class SeckillOrderDetailSeller extends StatelessWidget {

  // final SeckillOrderDetailData seckillOrderDetailData;
  final SeckillOrderDetailPageController controller;
  SeckillOrderDetailSeller({
    // required this.seckillOrderDetailData,
    required this.controller,
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: pageBgColor,
      body: ScrollConfigurationCommon(child: ListView(
        children: [
          SeckillOrderDetailGoodsArr(seckillOrderDetailData: controller.seckillOrderDetailData.value),
          SizedBox(height: 12.h),
          SeckillOrderDetailInfoBody(
            title: '订单信息', 
            children: [
              SeckillOrderDetailInfoItem(title: '订单编号', value: '${controller.seckillOrderDetailData.value.orderSn}', showCopy: true),
              SeckillOrderDetailInfoItem(title: '创建时间', value: '${controller.seckillOrderDetailData.value.createdAt}'),
            ]
          ),
          SizedBox(height: 12.h),
          SeckillOrderDetailInfoBody(
            title: '买家信息', 
            children: [
              SeckillOrderDetailInfoItem(title: '姓名', value: '${controller.seckillOrderDetailData.value.buyer!.accountName}'),
              SeckillOrderDetailInfoItem(title: '联系方式', value: '${controller.seckillOrderDetailData.value.buyer!.mobile}', showCopy: true),
            ]
          ),
        ],
      )),
      bottomNavigationBar: BottomAppBar(
        elevation: 0,
        child: Obx(() => Container(
          color: bgWhiteColor,
          height: controller.seckillOrderDetailData.value.status == 3 || controller.seckillOrderDetailData.value.status == 4 ? 56.h : 93.h,
          child: Column(
            children: [
              controller.seckillOrderDetailData.value.status == 3 || controller.seckillOrderDetailData.value.status == 4 ? Container() : ReplacementAgreement(
                consentAgreement: controller.consentAgreement.value, 
                onTap: () {
                  controller.consentAgreement.value = !controller.consentAgreement.value;
                }
              ),
              Container(
                height: 56.h,
                color: bgWhiteColor,
                padding: EdgeInsets.symmetric(horizontal: 12.w),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text.rich(
                      TextSpan(
                        text: '总价：',
                        style: TextStyle(
                          color: textBlackColor
                        ),
                        children: [
                          TextSpan(
                            text: '¥',
                            style: TextStyle(
                              color: mainTextColor,
                              fontSize: 18.sp,
                              fontWeight: FontWeight.bold
                            )
                          ),
                          TextSpan(
                            text: '${controller.seckillOrderDetailData.value.totalAmount}',
                            style: TextStyle(
                              color: mainTextColor,
                              fontSize: 22.sp,
                              fontWeight: FontWeight.bold
                            )
                          )
                        ]
                      )
                    ),
                    _getStatusBtn(controller.seckillOrderDetailData.value.status!, controller.seckillOrderDetailData.value.id!)
                  ],
                ),
              )
            ],
          ),
        )),
      ),
    );
  }

  /// 根据状态获取按钮
  /// status 1 => 待付款 2 => 待收款 3 => 已售出 4 => 已取消
  Widget _getStatusBtn(int status, int orderId) {
    List<Widget> children = [];
    if (status == 1) {
      children.add(Container(
        width: 120.w,
        child: ButtonUtil(
          text: '等待买家付款', 
          fontSize: 14.sp, 
          borderRadius: 18.w, 
          height: 36.h, 
          onTop: () {}
        )
      ));
    } else if (status == 2) {
      children.add(Container(
        width: 120.w,
        child: ButtonUtil(
          text: '我已确认收款', 
          fontSize: 14.sp, 
          borderRadius: 18.w, 
          height: 36.h, 
          onTop: () {
            controller.seckillOrderConfirmReceipt();
          }
        )
      ));
    }
    return Row(
      children: children,
    );
  }
}